
import React, { useState, useEffect } from 'react';
import './index.less';
import { useLocation, Outlet } from 'react-router-dom';
import NonePower from '@/router/config/nonePower';
import Header from '../home/header';
import Foot from '../home/foot';
import { useDispatch } from 'react-redux';
import { updateHeadActive } from '@/redux/state/com';

const Home = props => {
  const location = useLocation();
  const [menuList] = useState([]);
  const { route } = props;
  const dispatch = useDispatch();
  // 权限拦截
  function interceptRouter(item) {
    // 这里本地先关闭权限
    if (!menuList[item.name]) {
      return <item.element route={item} />;
    } else {
      return <NonePower></NonePower>;
    }
  }

  // 路由信息拦截-当路由切换时捕获目标的配置信息
  function infoRouter() {
    let list = route.children;
    for (let i = 0; i < list.length; i++) {
      if (location.pathname == list[i].path && list[i].meta.nav) {
        dispatch(updateHeadActive(list[i].meta.navValue));
        break;
      }
    }
  }

  useEffect(() => {
    infoRouter();
  }, [location]);
  return (
    <>
      <Header />
      <div className="main">
        <Outlet />
      </div>
      <Foot />
    </>
  );
};

export default Home;
